package main

import "net"

type User struct {
	Name string
	Addr string
	C    chan string
	conn net.Conn
}

func NewUser(conn net.Conn) *User {
	name := conn.RemoteAddr().String()
	newUser := &User{
		Name: name,
		Addr: name,
		C:    make(chan string),
		conn: conn,
	}
	go newUser.ListenMessages()

	return newUser
}

// listenmessages goroutine
func (this *User) ListenMessages() {
	for {
		message := <-this.C
		this.conn.Write([]byte(message + "\n"))
	}
}
